package Twice.day09.strings;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/8/12
 * @Version: 1.0
 */
public class StringBuilderDemo {
    public static void main(String[] args) {
        //利用String对象来构建一个stringBuilder 对象
        //类型的转换
        //java.lang.StringBuilder提供的StringBuilder(String str);
        //作用:将字符串类型转换成StringBuilder类型

        //StringBuilder里面没有串池的概念
        StringBuilder builder = new StringBuilder("sadf");
        System.out.println(builder.length());
        System.out.println(builder.append("sfdssf")); //对原来的进行直接操作

        //不一样的地方 - 容量
        System.out.println(builder.capacity());

        //默认容量是16
        System.out.println(new StringBuilder().capacity());//16

        StringBuilder bs = new StringBuilder("java");
        //删除指定多个下标处的值,返回一个StringBuilder - 被删除之后的值
        StringBuilder delete = bs.deleteCharAt(2);

        System.out.println(delete);

        System.out.println(new StringBuilder("sjfkasdad").delete(2,3));

        StringBuilder bu = new StringBuilder("sfdas");

        bu.insert(1,"sad");
        System.out.println(bu);

        System.out.println(new StringBuilder("sfasdha").reverse());

        //如何将StringBuilder转换成String类型
        StringBuilder stringBuilder = new StringBuilder("sldfhalg");
        String str = stringBuilder.toString();
        System.out.println(str);
    }
}
